#include <iostream>

#include <indent_str.h>
#include <cassert>

using std::cerr;
using std::cout;
using std::string;


// boost headers
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <substr_ref.h>

using boost::replace_all_copy;
using boost::iterator_range;
using boost::split;
using boost::is_any_of;
using boost::trim_left_copy_if;
using std::find;


#include <is_equal_to.h>
using std::string;
using std::vector;

int main (int argc, char *argv[])
{
    
    assert(indent_string("A line", 4) == "    A line");
    assert(indent_string("A line\n 2nd line", 4) == "    A line\n     2nd line");
    assert(indent_string("A line\n 2nd line\t3rdline", 4) == "    A line\n     2nd line\t3rdline");
    assert(indent_string("A line\n 2nd line\n\t3rdline", 4) == "    A line\n     2nd line\n    \t3rdline");


    //line_wrap_keeping_indent("A line\n 2nd line");
    string indent_str;
    string after_indent_str;
    get_initial_indent(	"   \tasdfasf", 
                            indent_str, 
                            after_indent_str);
    assert(indent_str == "   \t");
    assert(after_indent_str == "asdfasf");
    
    
    //	
    // test line wrapping simple text
    // 
    string long_text    =	"There isn't really any good reason to\t"
				"have two separate classes: this\t\t"     
				"separation is purely because of a "
				"technical limitation in some of today's "
				"C++ compilers. If the two classes were "
				"combined into one, then there would be "
				"no way to declare the return types of "
				"the iterator tag functions.";
    string wrapped_long_text = line_wrapped(long_text,	40);
    //std::cout <<             ">" << wrapped_long_text << "<\n";
    assert(wrapped_long_text == "There isn't really any good reason to\n"
				"have two separate classes: this\n"
				"separation is purely because of a\n"
				"technical limitation in some of today's\n"
				"C++ compilers. If the two classes were\n"
				"combined into one, then there would be\n"
				"no way to declare the return types of\n"
				"the iterator tag functions.");
    
    
    
    
    
    // 
    // just spaces should be wrapped without being gobbled
    //  
    std::cout <<             "\nTest: 120 spaces followed by 1\n";
    assert(line_wrapped(string(120, ' ') + "1",	40) == 
	    "                                        \n"
	    "                                        \n"
	    "                                        \n"
	    "1");
    // 
    // just spaces should be wrapped without being gobbled
    //  
    std::cout <<             "\nTest: beg + 50 spaces and end\n";
    assert(line_wrapped("beg" + string(50, ' ') + "end", 10) == "beg\nend");

    std::cout <<             "\nTest: 40 1s\n";
    assert(line_wrapped(string(40, '1'), 40) == "1111111111111111111111111111111111111111");


    std::cout <<             "\nTest: 40 2s + space\n";
    assert(line_wrapped(string(40, '2') + " ",	40) == "2222222222222222222222222222222222222222");

    std::cout <<             "\nTest: 40 3s + space + 1\n";
    assert(line_wrapped(string(40, '3') + " 1",	40) == "3333333333333333333333333333333333333333\n1");

    std::cout <<             "\nTest: 30 4s + comma + 8888888888\n";
    assert(line_wrapped(string(30, '4') + "," + "8888888888",	40) == "444444444444444444444444444444,\n8888888888");


    std::cout <<             "\nTest: 39 5s + comma + 8888888888\n";
    assert(line_wrapped(string(39, '5') + "," + "8888888888",	40) == "555555555555555555555555555555555555555,\n8888888888");
    
    std::cout <<             "\nTest: 39 6s + comma + space + 8888888888\n";
    assert(line_wrapped(string(39, '6') + "," + " 8888888888",	40) ==
	    "666666666666666666666666666666666666666,\n8888888888");
    
    std::cout <<             "\nTest: 40 7s + comma + space + 8888888888\n";
    assert(line_wrapped(string(39, '6') + "," + " 8888888888",	40) ==
	    "7777777777777777777777777777777777777777\n,8888888888");


    string long_indented_text    =	"There isn't really any good reason to have two separate classes:\n"
					"    This separation is purely because of a technical limitation in some of today's C++ compilers.\n"
					"  If the two classes were combined into one, then there would be no way to declare the return types of the iterator tag functions.";
    string wrapped_indented_text =  line_wrap_keeping_indent(long_indented_text, 40, 4);
    //std::cout <<             ">" << wrapped_indented_text << "<\n";
    assert(wrapped_indented_text == 	"There isn't really any good reason to\n"
					"have two separate classes:\n"
					"    This separation is purely because of\n"
					"    a technical limitation in some of\n"
					"    today's C++ compilers.\n"
					"  If the two classes were combined into\n"
					"  one, then there would be no way to\n"
					"  declare the return types of the\n"
					"  iterator tag functions.");
    

    std::cout << "done\n";
    return(0);
}






